package org.vectrics.recruiter.struts;


import org.apache.log4j.Category;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.InputStream;
import java.io.IOException;




public class TestHttpConnectionAction extends Action {
    private static Category log = Category.getInstance(TestHttpConnectionAction.class);
    
	public ActionForward execute(ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)	throws JspException {

				
		log.debug("execute() called, reading http parameters");

		try {
			
			String page = "http://www.vectrics.com";
			String urlStr = page;
			
			boolean test = false;
			log.info("AUTO LOGIN: " + urlStr);
			
			
			if (log.isDebugEnabled()) {
				log.debug("run() - sending request: " + urlStr);
			}
			
			URL url = new URL(urlStr);
			if (log.isDebugEnabled()) {
				log.debug("execute() - request => " + urlStr);
			}
			HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
			
			log.debug("run() - setting up http connection");
			httpURLConnection.setUseCaches(false);            
			httpURLConnection.setRequestMethod("POST");
			
			//httpURLConnection.connect();
			log.debug("run() - getting input stream from http connection");
			InputStream is = httpURLConnection.getInputStream();
		}
		catch (IOException ex) {
			String errorMsg = "IOException while doing connection test " +  ex.getMessage();
			log.error(errorMsg, ex);
		}
		
		return (mapping.findForward("success"));
        
	}



}